package type;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

public class Movie {
	private double meanRating;
	private int movieID;
	private String title;
	private Date releaseDate;
	private String imdbURL;
	private ArrayList<Integer> genres;
	private HashMap<User,Rating> ratingList;
	
	private static HashMap<Integer,String> _genreTable = null;
	public static void setGenreTable(HashMap<Integer,String> genreTable){
		_genreTable = genreTable;
	}
	
	public Movie(int movieID, String title, Date releaseDate, String imdbURL, ArrayList<Integer> genres){
		this.setMovieID(movieID);
		this.setTitle(title);
		this.setReleaseDate(releaseDate);
		this.setImdbURL(imdbURL);
		this.setGenres(genres);
		ratingList = new HashMap<User,Rating>();
	}
	
	@Override
	public String toString() {
		String str = "movieID:" + movieID + " title:" + title + " releaseDate:" + releaseDate + " imdbURL:" + imdbURL;
		if (_genreTable != null){
			str += "genres:( ";
			for (int i=0; i<genres.size(); ++i) {
				if(genres.get(i) == 1){
					str += _genreTable.get(new Integer(i)) + " ";
				}
			}
			str += ")";
		}
		return str;
	}

	public int getMovieID() {
		return movieID;
	}

	public void setMovieID(int movieID) {
		this.movieID = movieID;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	public String getImdbURL() {
		return imdbURL;
	}

	public void setImdbURL(String imdbURL) {
		this.imdbURL = imdbURL;
	}

	public ArrayList<Integer> getGenres() {
		return genres;
	}

	public void setGenres(ArrayList<Integer> genres) {
		this.genres = genres;
	}
	
	public HashMap<User,Rating> getRatingList() {
		return ratingList;
	}

	public void addRating(Rating rating) {
		this.ratingList.put(rating.getUser(), rating);
	}
	
	public void clearRating(){
		this.ratingList.clear();
	}
	
	public void computeMeanRating()
	{
		meanRating = 0.0;
		if(getRatingList().size() > 0)
		{
			for(Rating r: getRatingList().values())
			{
				meanRating += r.getRating();
			}
			meanRating /= getRatingList().size();
		}
	}
	
	public double getMeanRating()
	{
		return meanRating;
	}

	public void setMeanRating(double meanRating) {
		this.meanRating = meanRating;
	}

}
